package genedit.controller.interfaceActions;

import genedit.controller.ZoomState;
import genedit.model.Workspace;
import genedit.view.graph.GraphDocumentView;
import genedit.view.graph.GraphWorkArea;

import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

/**
 * Akcija zadužena za postavljanje zoom in stanja na aktivno stanje.
 * 
 * @author Nikola
 * @version 1.0 18/12/13
 */
public class GZoomInA extends AbstractAction {

	private static final long serialVersionUID = 1L;

	/**
	 * Singleton instanca akcije.
	 */
	private static GZoomInA instance = null;

	/**
	 * Akcija transformiše kursor u odgovarajući i postavlja zoom stanje na
	 * aktivno stanje.
	 */
	public void actionPerformed(ActionEvent arg0) {
		GraphDocumentView document = Workspace.getInstance().getActiveDocument();
		if (document == null)
			return;

		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Image image = toolkit.getImage("resources/icons/zoom-in-cursor.png");
		Point hotSpot = new Point(0, 0);
		Cursor cursor = toolkit.createCustomCursor(image, hotSpot, "CursorProba");

		GraphWorkArea workArea = ((GraphWorkArea) document.getWorkArea());
		workArea.setCursor(cursor);
		workArea.getController().setCurrentState(new ZoomState(workArea, 1));
	}

	public GZoomInA() {
		putValue(NAME, "Zoom In");
		putValue(SMALL_ICON, new ImageIcon("resources/icons/zoom_in.png"));
		putValue(MNEMONIC_KEY, KeyEvent.VK_PLUS);
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, ActionEvent.CTRL_MASK));
		putValue(SHORT_DESCRIPTION, "Zoom In");
	}

	public static AbstractAction getInstance() {
		if (instance == null)
			instance = new GZoomInA();
		return instance;
	}

}